package com.zone.example.handler;

import com.zone.weixin4j.annotation.WxMessageHandler;
import com.zone.weixin4j.exception.WeixinException;
import com.zone.weixin4j.message.TextMessage;
import com.zone.weixin4j.request.WeixinRequest;
import com.zone.weixin4j.response.TextResponse;
import com.zone.weixin4j.response.WeixinResponse;

/**
 * 输入 hello 回复 world
 */
/**
 * WxMessageHandler 注解声明处理消息内容的类
 * WxMessageInterceptor  注解声明拦截消息内容的类
 */
@WxMessageHandler
public class HelloMessageHandler extends TextMessageHandler {

	public boolean canHandle0(WeixinRequest request, TextMessage message)
			throws WeixinException {
		/**
		 * 用户输入hello时
		 */
		return message.getContent().equalsIgnoreCase("hello");
	}

	public WeixinResponse doHandle0(WeixinRequest request, TextMessage message)
			throws WeixinException {
		/**
		 * 返回用户「world」文本
		 */
		return new TextResponse("world");
	}

	/**
	 * 因为HelloMessageHandler和TextMessageHandler都会匹配到文本消息
	 * 所以这里需要提高下权重(大于TextMessageHandler就行了) > TextMessageHandler
	 */
	public int weight() {
		return super.weight() + 1;
	}
}
